const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curNav: 2,
    navTypes:[
      {label: '未开始', type: 2},
      {label: '进行中', type: 3},
      {label: '已结束', type: 4},
    ],
    dataList:[],
    isLoading: false,
    search:{
      enterprise_uid: "",
      pageNum: 1,
      pageSize: 10,
      state: 2,
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    let userInfo = wx.getStorageSync('userInfo')
    this.data.search.enterprise_uid = userInfo.enterpriseUid
    this.data.search.pageNum = 1
    this.setData({
      search: this.data.search,
    })
    this.getDataList()
  },
  reload() {
    let filterForm = wx.getStorageSync('jl_search')
    filterForm.pageNum = 1
    this.setData({
      dataList: [],
      curNav: filterForm.applyState,
      search: Object.assign({}, this.data.search, filterForm)
    })
    this.getDataList()
  },
  onNavChange(e){
    let {type} = e.currentTarget.dataset
    this.data.search.pageNum = 1
    this.data.search.state = type
    this.setData({
      curNav: type,
      search: this.data.search,
      dataList:[]
    })
    this.getDataList()
  },
  getDataList(){
    let _this = this
    this.setData({ isLoading: true })
    wx.showLoading()
    wx.request({
      url: url + 'jobFair/getJobFairEnterprisesByPage',
      // header:{ 'Content-Type': 'application/json',},
      data: this.data.search,
      method: "GET",
      success(res){
        let resData = res.data
        if(resData.code != 200 || !resData.data){
          wx.showToast({
            title: res.data.msg,
            icon:'error'
          })
          return
        }
        let dataList = (resData.data.content || []).filter(item => item.id)
        if(_this.data.search.pageNum > 1 && dataList.length === 0){
          wx.showToast({
            title: '到底了~~',
            icon:'none'
          })
          return
        }
        _this.setData({
          dataList: [..._this.data.dataList, ...dataList]
        })
      },
      complete(){
        wx.hideLoading()
        _this.setData({ isLoading: false})
      }
    })
  },
  toMeetDetail(e){
    let {id, status} = e.currentTarget.dataset
    let nid = this.data.curNav
    wx.navigateTo({
      url: '/HomePage/jobfairdetail/jobfairdetail?id='+id +'&status='+status+'&nid='+ nid,
    })
  },
  onReachBottom: function () {
    this.data.search.pageNum++
    this.setData({
      search: this.data.search
    })
    this.getDataList()
  },
  showReason(e){
    let { reason } = e.currentTarget.dataset
    wx.showModal({
      title: '提示',
      content: reason,
      showCancel: false,
      success() {}
    })
  }
})